package background

import (
	"clouds.lgb24kcs.cn/controllers/background/request"
	"clouds.lgb24kcs.cn/errorx"
	"clouds.lgb24kcs.cn/global"
	"clouds.lgb24kcs.cn/models"
	"clouds.lgb24kcs.cn/utils"
	"fmt"
	"github.com/gin-gonic/gin"
)

type DeleteCarousel struct {
}

var DeleteCarouselApi DeleteCarousel

func (d *DeleteCarousel) Delete(c *gin.Context, req request.DeleteCarouselReq, userId int64) {
	info := models.Carousel{}
	tx := global.APP.DB.Where("id=? and user_id=?", req.ID, userId).Delete(&info)
	if tx.Error != nil {
		global.APP.Log.Error(fmt.Sprintf("轮播图删除错误：%s", tx.Error))
		utils.Fail(c, errorx.CarouselList, fmt.Sprintf("轮播图删除错误：%s", tx.Error))
	} else if tx.RowsAffected == 0 {
		utils.Fail(c, errorx.CarouselList, fmt.Sprintf("没有该数据"))
	} else {
		utils.Success(c, 0, "删除成功")
	}
}
